package com.poly.police.monitor.common.uid.builder;


import com.poly.police.monitor.common.uid.sequence.Sequence;
import com.poly.police.monitor.common.uid.sequence.impl.CachedSnowflakeSequence;

/**
 * 基于雪花算法，序列号生成器构建者
 * Created by xuan on 2018/5/30.
 */
public class CachedSnowflakeSequenceBuilder implements SequenceBuilder {

    /**
     * 数据中心ID，值的范围在[0,31]之间，一般可以设置机房的IDC[必选]
     */
    private long datacenterId;
    /**
     * 工作机器ID，值的范围在[0,31]之间，一般可以设置机器编号[必选]
     */
    private long workerId;

    private int boostPower;

    @Override
    public Sequence build() {
        CachedSnowflakeSequence sequence = new CachedSnowflakeSequence();
        sequence.setDatacenterId(this.datacenterId);
        sequence.setWorkerId(this.workerId);
        sequence.setBoostPower(this.boostPower);
        sequence.init();
        return sequence;
    }

    public static CachedSnowflakeSequenceBuilder create() {
        CachedSnowflakeSequenceBuilder builder = new CachedSnowflakeSequenceBuilder();
        return builder;
    }

    public CachedSnowflakeSequenceBuilder datacenterId(long datacenterId) {
        this.datacenterId = datacenterId;
        return this;
    }
    
    public CachedSnowflakeSequenceBuilder workerId(long workerId) {
        this.workerId = workerId;
        return this;
    }

    public CachedSnowflakeSequenceBuilder boostPower(int boostPower) {
        this.boostPower = boostPower;
        return this;
    }
}
